package com.example.uploadphotos;

import androidx.appcompat.app.AppCompatActivity;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.io.FileNotFoundException;

public class Xian_Activity extends AppCompatActivity {
    private Button btnText;
    private ImageView picture;
    String info = "",index = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xian_);
        picture = findViewById(R.id.img_picture);
        btnText = findViewById(R.id.btn_text);

        btnText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initData();
            }
        });
    }

    private void initData() {

        MySQLite dbHelper = new MySQLite(Xian_Activity.this,"user",null,1);
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cursor = db.query("user",null,null,null,null,null,null);

        while (cursor.moveToNext()){
            index = cursor.getString(cursor.getColumnIndex("FLAG"));
            info = cursor.getString(cursor.getColumnIndex("PHOTO"));
            Log.d("----show-Photo","--"+info);
            if (index.equals("1")){		//	相册
                Bitmap bitmap = BitmapFactory.decodeFile(info);
                picture.setImageBitmap(bitmap);
            }else if (index.equals("2")){	//	拍照
                Uri imgUri = Uri.parse(info);
                try {
                    Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imgUri));
                    picture.setImageBitmap(bitmap);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}


